package com.yuexun.dhdoctor.module.meetingNew.presenter.impl;


import com.yuexun.dhdoctor.base.BaseEntity;
import com.yuexun.dhdoctor.module.meetingNew.bean.MeetingNewCheckStateBean;
import com.yuexun.dhdoctor.module.meetingNew.bean.MeetingNewDetailBean;
import com.yuexun.dhdoctor.module.meetingNew.model.IMeetingNewDetailModel;
import com.yuexun.dhdoctor.module.meetingNew.presenter.IMeetingNewDetailPresenter;
import com.yuexun.dhdoctor.module.meetingNew.ui.view.IMeetingNewDetailView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by work-jx on 2016/11/15.
 */
public class MeetingNewDetailPresenter implements IMeetingNewDetailPresenter {
    private IMeetingNewDetailView view;
    private IMeetingNewDetailModel model;

    public MeetingNewDetailPresenter(IMeetingNewDetailModel model, IMeetingNewDetailView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void getMeetingDetail(Map<String, String> praise) {
        model.getMeetingDetail(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<MeetingNewDetailBean>>() {

                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("网络连接失败，请检查网络连接");
                    }

                    @Override
                    public void onNext(BaseEntity<MeetingNewDetailBean> meetingDetailBean) {
                        view.showMeetingDetail(meetingDetailBean);
                    }
                });
    }

    @Override
    public void getMeetingCheckState(Map<String, String> praise) {
        model.getMeetingCheckState(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<MeetingNewCheckStateBean>>() {

                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("查询签到状态失败,请检查网络连接");
                    }

                    @Override
                    public void onNext(BaseEntity<MeetingNewCheckStateBean> meetingCheckStateBean) {
                        view.showMeetingCheckState(meetingCheckStateBean);
                    }
                });
    }

    @Override
    public void getMeetingCheck(Map<String, String> praise) {
        model.getMeetingCheck(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<String>>() {

                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("签到失败请求失败,请检查网络连接");
                    }

                    @Override
                    public void onNext(BaseEntity<String> meetingBeanCheckBean) {
                        view.showMeetingCheck(meetingBeanCheckBean);
                    }
                });
    }
}
